package com.xdf.xzymanagementsystem.service;

import com.xdf.xzymanagementsystem.dao.SysPermissionToolMapper;
import com.xdf.xzymanagementsystem.entity.SysPermissionTool;
import com.xdf.xzymanagementsystem.entity.SysUser;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Optional;

/**
 * @author chanchaw
 * @create 2022-08-25 14:34
 */
@Service
public class SysPermissionToolServiceImpl implements SysPermissionToolService{
    @Autowired
    private SysUserService sysUserService;
    @Autowired
    private SysPermissionToolMapper dao;

    @Override
    public int deleteByPrimaryKey(Integer iid) {
        return dao.deleteByPrimaryKey(iid);
    }

    @Override
    public int insert(SysPermissionTool row) {
        return dao.insert(row);
    }

    @Override
    public int insertSelective(SysPermissionTool row) {
        return dao.insertSelective(row);
    }

    @Override
    public SysPermissionTool selectByPrimaryKey(Integer iid) {
        return dao.selectByPrimaryKey(iid);
    }

    @Override
    public int updateByPrimaryKeySelective(SysPermissionTool row) {
        return dao.updateByPrimaryKeySelective(row);
    }

    @Override
    public int updateByPrimaryKey(SysPermissionTool row) {
        return dao.updateByPrimaryKey(row);
    }

    @Override
    public List<SysPermissionTool> selectByParam(SysPermissionTool record) {
        String loginName = record.getRemark();
        SysUser user = new SysUser();
        try {
            user = sysUserService.selectByLoginName(loginName);
        } catch (Exception e) {
            throw new RuntimeException(e);
        }
        SysPermissionTool tool = new SysPermissionTool();
        tool.setUser_id(Optional.ofNullable(user.getId()).orElse(0));

        return dao.selectByParam(tool);
    }
}
